package com.hbnu.controller;

import com.hbnu.bean.Door;
import com.hbnu.bean.Order;
import com.hbnu.service.DoorService;
import com.hbnu.service.OrderService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


import javax.annotation.Resource;
import java.util.List;
/**
 * @Auther: hjx
 * @Date: 2023/4/19 09:37
 * @Description:订单管理模块
 */


@Controller
public class OrderController {
    @Resource
    private OrderService orderService;
    @Resource
    private DoorService doorService;

    //查询所有订单信息
    @RequestMapping("/orderList")
    public String findAllOrders(Model model) {
        List<Order> orderList = orderService.findAllOrders();
        model.addAttribute("orderList", orderList);
        List<Door> doorList = doorService.findAllDoors();
        model.addAttribute("doorList", doorList);
        return "order_list";
    }

    //查询出所有页面寄存数据
    @RequestMapping("/findAllDoorToOrderAdd")
    public String findAllDoorToOrderAdd(Model model) {
        List<Door> doorList = doorService.findAllDoors();
        //返回doorList到前端，供前端查询下拉列表
        model.addAttribute("doorList", doorList);
        return "order_add";
    }

    //订单添加
    @RequestMapping("/orderAdd")
    public String NewOrderAdd(Order order) {
        orderService.NewOrderAdd(order);
        return "redirect:/orderList";
    }
    //订单删除

    @RequestMapping("/orderDelete")
    public String DeleteOrderById(Integer id) {
        orderService.DeleteOrderById(id);
        return "redirect:/orderList";
    }

    //订单修改回传orderUpdate方法
    @RequestMapping("/orderInfo")
    public String orderInfo(Integer id, Model model) {
        List<Door> doorList = doorService.findAllDoors();
        model.addAttribute("doorList", doorList);
        Order order = orderService.findOrderById(id);
        model.addAttribute("order", order);
        return "order_update";
    }

    //订单修改具体方法
    @RequestMapping("/orderUpdate")
    public String UpdateOrder(Order order) {
        orderService.UpdateOrder(order);
        return "redirect:/orderList";
    }


}
